﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data;

namespace DAL
{
   public class studentDAL
    {
        public static DataTable getALL() {
            string sql = "select * from student";
            DataTable dt = DBHelper.ExcuteTable(sql);
            return dt;
        }
        public static List<student> getlist()
        {
            DataTable dt = getALL();
            List<student> list = new List<student>();
            return list;
        }
        public static int deleteBYID(int sno)
        {
            string sql = string.Format("delete student where sno={0}", sno);
            int num = DBHelper.ExecuteNonQuery(sql);
            return num;
        }
        public static int addstuinfo(student model)
        {
            string sql = string.Format("insert into student values({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}')",
                model.sno,model.password,model.name,model.age,model.sex,model.birthtime,model.addres,model.classes,model.tel,model.zhuanye,model.graduation);
          int dt=  DBHelper.ExecuteNonQuery(sql);
            return dt;
        }
        public static student getID(int sno)
        {
            string sql = "select * from student where sno=" + sno;
            DataTable dt =  DBHelper.ExcuteTable(sql);
            if (dt.Rows.Count > 0)
            {
                student model = new student();
                model.sno = Convert.ToInt32(dt.Rows[0]["sno"]);
                model.password = dt.Rows[0]["password"].ToString();
                model.name  = dt.Rows[0]["name"].ToString();
                model.age = dt.Rows[0]["age"].ToString();
                model.sex = dt.Rows[0]["sex"].ToString();
                model.birthtime = dt.Rows[0]["birthtime"].ToString();
                model.addres = dt.Rows[0]["addres"].ToString();
                model.classes = dt.Rows[0]["classes"].ToString();
                model.tel = dt.Rows[0]["tel"].ToString();
                model.zhuanye = dt.Rows[0]["zhuanye"].ToString();
                model.graduation = dt.Rows[0]["graduation"].ToString();


                return model;
            }
            return null;
        }
        public static int updatestu(student model)
        {
            string sql = string.Format("update student set password='{0}',name='{1}',age='{2}',sex='{3}',birthtime='{4}',addres='{5}',classes='{6}',tel='{7}',zhuanye='{8}',graduation='{9}' where sno={10}",
                model.password, model.name, model.age, model.sex, model.birthtime, model.addres, model.classes, model.tel, model.zhuanye, model.graduation, model.sno);
                return  DBHelper.ExecuteNonQuery(sql);       
        
        }
    }
}
